<div class="layui-card">
    <div class="layui-card-header">
        <h2 class="header-title">招聘信息管理中心</h2>
        <span class="layui-breadcrumb pull-right">
          <a href="#!console">首页</a>
          <a><cite>招聘信息管理</cite></a>
        </span>
    </div>
    <div class="layui-card-body">
        <div class="layui-form toolbar">
            搜索：
            <select id="recruit-search-key">
                <option value="">-请选择-</option>
                <option value="id">ID</option>
                <option value="recruitName">职位名称</option>
                <option value="address">位置</option>
                <option value="workExperience">工作经验</option>
                <option value="education">学历</option>
                <option value="companyName">公司名称</option>
                <option value="wage">工资</option>
                <option value="createTime">发布时间</option>
            </select>&emsp;
            <input id="recruit-search-value" class="layui-input search-input" type="text" placeholder="输入关键字"/>&emsp;
            <button id="recruit-btn-search" class="layui-btn icon-btn"><i class="layui-icon">&#xe615;</i>搜索</button>
            <button id="recruit-btn-add" class="layui-btn icon-btn"><i class="layui-icon">&#xe654;</i>添加</button>
            <button id="recruit-btn-export" class="layui-btn icon-btn"><i class="layui-icon">&#xe601;</i>导出</button>
        </div>

        <table class="layui-table" id="recruit-table" lay-filter="recruit-table"></table>
    </div>
</div>


<!-- 表格操作列 -->
<script type="text/html" id="recruit-table-bar">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">修改</a>
    <a class="layui-btn layui-btn-xs" lay-event="del">删除</a>
</script>

<script>
    layui.use(['form', 'table', 'util', 'config', 'admin'], function () {
        var form = layui.form;
        var table = layui.table;
        var config = layui.config;
        var layer = layui.layer;
        var util = layui.util;
        var admin = layui.admin;


        // 添加按钮绑定权限
        if(!admin.hasPerm('recruit:recruit/add')) {
            $('#recruit-btn-add').hide();
        }

        // 渲染表格
        var aa = table.render({
            elem: '#recruit-table',
            // url: config.base_server + 'user_query.json',
            url: config.base_server + 'api-recruit/recruit/selectCompanyName?access_token='+
                config.getToken().access_token+'&userId='+config.getUser().id,
            method: 'POST',
            where: {
                // access_token: config.getToken().access_token

            },
            page: true,
            cols: [[
                {type: 'numbers'},
                {field: 'id', sort: true, title: '编号'},
                {field: 'recruitName', sort: true, title: '招聘名称'},
                {field: 'address', sort: true, title: '位置'},
                {field: 'workExperience', sort: true, title: '工作经验'},
                {field: 'education', sort: true, title: '学历'},
                {field: 'skill', sort: true, title: '技能'},
                {field: 'companyName', sort: true, title: '公司名称'},
                {field: 'wage', sort: true, title: '工资'},
                {field: 'jobRequirements', sort: true, title: '岗位要求'},
                {field: 'jobResponsibilities', sort: true, title: '岗位职责'},
                {field: 'workRequirements', sort: true, title: '上班要求'},
                {field: 'jobBenefits', sort: true, title: '职位福利'},
                {field: 'companyInformation', sort: true, title: '公司信息'},
                {field: 'companyTechniciansNum', sort: true, title: '在职人数'},
                {field: 'personnel', sort: true, title: '咨询负责人'},
                {field: 'sex', sort: true, title: '性别',templet:function (d) {
                        return d.sex==0?"男":"女"
                    }},
                {field: 'createTime',
                    sort: true, templet: function (d) {
                        return util.toDateString(d.createTime);
                    }, title: '创建时间'
                },
                {field: 'updateTime',
                    sort: true, templet: function (d) {
                        return util.toDateString(d.updateTime);
                    }, title: '更新时间'
                },
                {align: 'center', toolbar: '#recruit-table-bar', title: '操作',width: 150}
            ]]
        });

        // 添加按钮点击事件
        $('#recruit-btn-add').click(function () {
            showEditModel();
        });

        // 导出按钮绑定权限
        if(!admin.hasPerm('recruit:down')) {
            $('#recruit-btn-export').hide();
        }

        // 工具条点击事件
        table.on('tool(recruit-table)', function (obj) {
            var data = obj.data;
            var layEvent = obj.event;

            if (layEvent === 'edit') { // 修改
                showEditModel(data);
            } else if (layEvent === 'del') { // 删除
                layer.confirm('确定删除这条数据吗？', function () {
                    layer.load(2);
                    admin.req('api-recruit/recruit/deleteRecruitInformation/'+obj.data.id, {}, function (data) {
                        layer.closeAll('loading');
                        if (data.code == 0) {
                            layer.msg(data.msg, {icon: 1, time: 500});
                            table.reload('recruit-table', {});
                        } else {
                            layer.msg(data.msg, {icon: 2, time: 500});
                        }
                    }, 'POST');
                });
            }
        });

        //显示表单弹窗
        var showEditModel = function (data) {
            //修改sex值
            if (data){
                data.sex = data.sex+'';
            }
            admin.putTempData('t_recruit', data);
            var title = data ? '修改招聘信息' : '添加招聘信息';
            admin.popupCenter({
                title: title,
                path: 'pages/system/recruit_form.html',
                finish: function () {
                    table.reload('recruit-table', {});
                }
            });
        };

        // 搜索按钮点击事件
        $('#recruit-btn-search').click(function () {
            var key = $('#recruit-search-key').val();
            var value = $('#recruit-search-value').val();
            table.reload('recruit-table', {where: {userId:config.getUser().id,searchKey: key, searchValue: value}});
        });

        // 导出
        $('#recruit-btn-export').click(function () {
            var key = $('#recruit-search-key').val();
            var value = $('#recruit-search-value').val();
            admin.req('api-recruit/recruit/selectCompanyName', {userId:config.getUser().id,searchKey: key, searchValue: value}, function (data) {
                layer.closeAll('loading');
                if (data.code == 0) {
                    table.exportFile(aa.config.id, data.data);
                    layer.msg(data.msg, {icon: 1, time: 500});
                } else {
                    layer.msg(data.msg, {icon: 2, time: 500});
                }
            }, 'POST');

        });
    });
</script>